<template>
  <van-row class="panel-rectify-operate">
    <van-cell-group title="制定整改措施">
      <template v-if="assessType === $vo.AssessType.DEPT + ''">
        <van-row class='radio-area' gutter="10">
          <van-radio-group v-model="apprType" direction="horizontal">
            <van-col span="10" offset="2">
              <van-radio name="0">一级审核</van-radio>
            </van-col>
            <van-col span="10" offset="2">
              <van-radio name="1">二级审核</van-radio>
            </van-col>
          </van-radio-group>
        </van-row>
        <van-row class="split-h last-row"/>
        <van-field v-if="apprType === '1'" required label-width="100px" label="审核部门" input-align="right" readonly placeholder="请指定整改措施审核部门" v-model="dept" @click="showPageDeptList=true"/>
      </template>
      <van-field required label-width="100px" label="整改期限" input-align="right" readonly placeholder="请选择整改完成时间" :value="dateValue" @click="showCalendar = true"/>
      <van-field required label-width="100px" label="整改措施" input-align="right" readonly placeholder="请在下方输入详细整改措施"/>
      <van-field class='input-area' v-model="plan" rows="2" autosize type="textarea" maxlength="1000" placeholder="请输入详细整改措施" show-word-limit/>
      <card-receivers :parentPath="parentDept" :showChildren="1" v-model="receivers"/>
      <van-row class="split-h"/>
      <van-row class='operate-area' gutter="10">
        <van-col span="12">
          <van-button type="info" @click="submit">提交</van-button>
        </van-col>
        <van-col span="12">
          <van-button type="warning" @click="rollBack">退回</van-button>
        </van-col>
      </van-row>
    </van-cell-group>
    <van-calendar get-container="body" v-model="showCalendar" @confirm="onSelectDate" />
    <van-popup
      v-model="showPageDeptList"
      position="right"
      get-container="body"
      style="width: 100%; height: 100%; background-color: #F9F9F9">
      <page-dept-list v-if="showPageDeptList" @onCancel="showPageDeptList = false" @onConfirm="endSelectDept"/>
    </van-popup>
  </van-row>
</template>

<script>
import CardReceivers from '@/views/common/card/CardReceivers'
import PageDeptList from '@/views/rectify/common/page/PageDeptList'
import ApiMixin from '@/mixins/ApiMixin'
export default {
  name: 'PanelRectifyPlan',
  mixins: [ApiMixin],
  components: { PageDeptList,CardReceivers },
  data () {
    return {
      apprType: '0',
      apprDept: '',
      dateValue: '',
      showCalendar: false,
      showPageDeptList: false,
      plan: '',
      parentDept: this.rectify.reviewDept,
      formData: this.$vo.createRectifyFormData(),
      receivers: []
    }
  },
  methods: {
    endSelectDept (value) {
      console.info("value",value)
      this.apprDept = value
      this.parentDept = value
      this.showPageDeptList = false
    },
    rollBack () {
      this.formData.op = this.$vo.RectStatus.REJECT
      // 提交
      this.doUpdateRectify()
    },
    submit () {
      if (this.apprType === '1') {
        if (this.apprDept.trim() === '') {
          this.$dialog.alert({
            message: '请指定整改措施审核部门'
          })
          return
        }
        this.rectify.manage_dept = this.apprDept.trim()
        this.rectify.flow_type = 1
      }
      if (this.dateValue.trim() === '') {
        this.$dialog.alert({
          message: '请输入整改完成时间'
        })
        return
      }
      if (this.plan.trim() === '') {
        this.$dialog.alert({
          message: '请输入整改措施'
        })
        return
      }
      if (this.receivers.length === 0) {
        this.$dialog.alert({
          message: '请选择接收人员'
        })
        return
      }
      this.formData.op = this.$vo.RectStatus.PLAN
      this.formData.receivers = this.receivers
      this.rectify.rectify_deadline = this.dateValue
      this.rectify.rectify_content = this.plan.trim()
      // 提交
      this.doUpdateRectify()
    },
    onSelectDate (date) {
      this.dateValue = `${date.getFullYear()}-${date.getMonth() + 1}-${date.getDate()}`
      this.showCalendar = false
    }
  },
  computed: {
    dept: function () {
      return this.apprDept.substr(this.apprDept.indexOf('/') + 1)
    }
  },
  watch: {
    apprType: function (val) {
      if(val == 0){
        this.parentDept = this.rectify.reviewDept
      }
    },
  }
}
</script>

<style scoped lang="less">
</style>
